#ifndef IMPORTER_H
#define IMPORTER_H

#include "Sprite.h"
#include "Mesh.h"
#include "Texture.h"
#include "XMLParser/XMLParser.h"
#include "Node.h"

#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>

#include <map>

//Singleton Class
class ENGINE_API Importer
{
public:
   Importer(Renderer* renderer) { m_pRenderer = renderer; }
   ~Importer(){}

   bool createSprite (const char* name, Sprite* sprite);
   Texture::TexturePtr getTexture (const char* filename);

   bool importResources(const char* xmlTextureFileName); //llama a loadSprite por cada sprite encontrado
  
   bool importModel(const std::string& filePath);

   bool recursiveLoad(const aiScene* scene, aiNode* node, Node* resultNode);

   /*
      name: filepath or filename
   */
   Node* getModel(std::string name);

   std::string extractFileName(std::string filePath);
   std::string extractFileLocation(std::string filePath);
   

private:
   std::map<std::string, Sprite*> m_spriteMap;
   std::map<std::string, Texture::TexturePtr> m_pTextureMap;
   std::map<std::string, AnimationInfo::AnimationInfoPtr> m_animationMap;

   std::map<std::string, Node*> m_nodeMap;

   Renderer* m_pRenderer;
   Sprite* m_pCurrentSprite;

   std::string m_currentModelPath;

   bool importSprite (XMLNode& spriteNode);
   bool importTexture (XMLNode& textureNode);
   bool importAnimation (XMLNode& animationNode);

   D3DXMATRIX convertToDxMatrix(aiMatrix4x4 aiMatrix);
   
   Mesh* convertToEngineMesh( aiMesh* pAiMesh, const aiScene* pAiScene );

   void importMeshMaterial( aiMesh* pAiMesh, const aiScene* pAiScene, Mesh* pEngineMesh );
   bool importMeshTexture(const std::string &texturePath);
};

#endif//IMPORTER_H